package njuflink;

import java.sql.*;

public class javaConnectMysql {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
//        1.加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
//        2.用户信息和url
        String url = "jdbc:mysql://47.98.99.88:3306/cclab";
        String username="practice";
        String password="123456";
//        3.连接成功，数据库对象 Connection
        Connection connection = DriverManager.getConnection(url,username,password);
//        4.执行SQL对象Statement，执行SQL的对象
        Statement statement = connection.createStatement();
//        5.执行SQL的对象去执行SQL，返回结果集
        String sql = "SELECT *FROM repo_info limit 100;";
        ResultSet resultSet = statement.executeQuery(sql);
        while(resultSet.next()){
            System.out.println("user_name="+resultSet.getString("user_name"));
            System.out.println("repo_name="+resultSet.getString("repo_name"));
            System.out.println("language="+resultSet.getString("language"));
            System.out.println("description="+resultSet.getString("description"));
            System.out.println("fork_count="+resultSet.getString("fork_count"));
            System.out.println("star_count="+resultSet.getString("star_count"));
            System.out.println("issue_count="+resultSet.getString("issue_count"));
            System.out.println("size="+resultSet.getString("size"));
            System.out.println("license="+resultSet.getString("license"));
        }
//        6.释放连接
        resultSet.close();
        statement.close();
        connection.close();
    }
}


